package com.ctshk.rpc.finance.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.finance.dto.advance.AdvanceChargeAmountDTO;
import com.ctshk.rpc.finance.dto.paidin.CurrencyAmountCountDTO;
import com.ctshk.rpc.finance.entity.FinanceAdvanceChargeCurrencyAmount;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 财务预收款申请汇总表 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-04-08
 */
public interface FinanceAdvanceChargeCurrencyAmountMapper extends BaseMapper<FinanceAdvanceChargeCurrencyAmount> {

    /**
     * 查询汇总信息
     * @param id
     * @return
     */
    @Select("SELECT id,currency,exchange_rate,money_amount,available_amount,amount_used,remaining_amount\n" +
            "FROM t_finance_advance_charge_currency_amount\n" +
            "WHERE advance_charge_id = #{advance_charge_id} AND is_deleted = 0")
    List<AdvanceChargeAmountDTO> queryByCharge(@Param("advance_charge_id") Long id);

    /**
     * 申请付款-查询供应商预付款额度
     * @param supplierId
     * @return
     */
    @Select("SELECT currency_id AS id,currency,remaining_amount AS amount\n" +
            "FROM t_finance_advance_charge_currency_amount\n" +
            "WHERE supplier_id = #{supplier_id} AND is_deleted = 0 GROUP BY currency_id")
    List<CurrencyAmountCountDTO> sumCurrencyAmountBySupplier(@Param("supplier_id") Long supplierId);
}
